#include "CalendarComboBoxLikeWidget.h"
#include <QApplication>

namespace UserManagementSystem {
CalendarComboBoxLikeWidget::CalendarComboBoxLikeWidget(QWidget *parent)
    : QFrame{parent}
{

    m_mainLayout=new QHBoxLayout(this);


    m_birLabel=new QLabel("Label",this);

    m_arrowBtn=new QPushButton("下箭头",this);
    m_calendar=new QCalendarWidget();

    // m_calendar->hide();
    InitDefaultLayout();
    connect(m_arrowBtn,&QPushButton::clicked,this,&CalendarComboBoxLikeWidget::On_arrow_clicked);

    //选择日期改变函数
    connect(m_calendar,&QCalendarWidget::selectionChanged,this,[this](){

        QDate date=m_calendar->selectedDate();
        m_birLabel->setText(date.toString());


    });

}

QLabel *CalendarComboBoxLikeWidget::GetBirthLabel() const
{
    return m_birLabel;
}

void CalendarComboBoxLikeWidget::On_arrow_clicked()
{
    qDebug()<<"点击了下拉框";

    QPoint global_pos=this->mapToGlobal(this->rect().bottomLeft());
    m_calendar->move(global_pos);
    m_calendar->show();

}

void CalendarComboBoxLikeWidget::InitDefaultLayout()
{

    m_mainLayout->setContentsMargins(0,0,0,0);
    m_mainLayout->addWidget(m_birLabel);

    m_mainLayout->addStretch(1);
    m_mainLayout->addWidget(m_arrowBtn);


    //移到左下的位置
    InitDefaultStyle();
}

void CalendarComboBoxLikeWidget::InitDefaultStyle()
{
    // this->setFixedHeight(20);
    this->m_calendar->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);

    //这个窗口样式为圆角
    QString Btn_sty=(R"(
    QPushButton {
            border: 1px solid black;              /* 无边框 */
            background-color: white; /* 浅蓝色背景 */

            border-radius: 2px;
        }
    )");
    m_birLabel->setStyleSheet("padding: 4px;");


    m_arrowBtn->setStyleSheet(Btn_sty);
}

void CalendarComboBoxLikeWidget::LoadIcon()
{

}

}

